package email.com.gmail.wynnwktran.fruitbasket;

import java.util.LinkedList;
import java.util.List;

/**
 * Representation of a fruit basket,
 * created for a demonstration of typecasting.
 * @author Wynn
 */

public class FruitBasket {
	
	/**
	 * A list of fruits.
	 */
	List<Fruit> fruits;
	
	/**
	 * Constructor for FruitBasket.
	 */
	public FruitBasket(){
		fruits = new LinkedList<Fruit>();
	}
	
	/**
	 * Adds a fruit to the basket.
	 * @param f the fruit to be added
	 */
	public void addFruit(Fruit f) {
		fruits.add(f);
	}
	
	/**
	 * Gets the fruits in the basket.
	 * @return A list of fruits contained in the basket.
	 */
	public List<Fruit> getFruits() {
		return fruits;
	}
	
	/**
	 * Gets all the apples in the basket.
	 * @return A list of apples contained in the basket.
	 */
	public List<Apple> getApples() {
		List<Apple> apples = new LinkedList<Apple>();
		for (Fruit f : fruits) {
			if (f instanceof Apple) {
				apples.add((Apple) f);
			}
		}
		return apples;
	}
	
	/* Probably not the best example ...
	 public void eatAllFruit() {
		for (Fruit f : fruits) {
			if (f instanceof Apple) {
				boolean appleHasWorm = ((Apple) f).checkForWorm();
				if (appleHasWorm == false) {
					f.eat();
				}
			} else {
				f.eat();
			}
		}
	} */

}
